package com.wf.controller;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.wf.dto.ContractDTO;
import com.wf.dto.TaskDTO;
import com.wf.exception.ApartmentException;
import com.wf.service.AgencyService;
import com.wf.service.ContractInfoService;
import com.wf.service.MessageInfoService;
import com.wf.vo.Result;
import com.wf.vo.TaskRepresentationVO;
import com.wf.vo.TaskVO;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.history.HistoricActivityInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *  签约接口
 * @author mpk
 */
@RestController
@Slf4j
@DS("flowable")
@CrossOrigin
@RequestMapping("/agency")
public class AgencyController {


    @Autowired
    private AgencyService agencyService;

    @Autowired
    MessageInfoService messageInfoService;
    @Autowired
    ContractInfoService contractInfoService;

    /**
     * 签约申请
     */

    @PostMapping(value="/process")
    public Result startProcessInstance(@RequestBody ContractDTO contractDTO) throws ApartmentException {


        agencyService.startAgencyProcess(contractDTO);

        return Result.success();

    }
    /**
     * 获取签约任务
     * @param assignee 处理人ID
     * @return
     */

    @GetMapping("/tasks/{assignee}")
    public Result getTasks(@PathVariable String assignee) {

        List<TaskVO> taskRepresentations = agencyService.getTasks(assignee);

        return Result.success(taskRepresentations);
    }

    /**
     * 人员审批
     * @param taskDTO
     */
    @PostMapping("/complete")
    public Result  completeTask(@RequestBody TaskDTO taskDTO)
    {
        log.info(String.valueOf(taskDTO));
        agencyService.completeTask(taskDTO);
        return Result.success();
    }


    /**
     * 获取某人处理的记录
     * @param assignee 处理人ID
     * @return
     */
    @GetMapping("history")
    public Result getHistory(String assignee)
    {

        List<HistoricActivityInstance> history = agencyService.getHistory(assignee);

        return Result.success(history);

    }


}